/*
两个传感器中断归零的测试代码
*/

// the setup function runs once when you press reset or power the board
#include <MultiStepper.h>
#include <AccelStepper.h>
AccelStepper step1(1, 9, 8);
AccelStepper step2(1, 5, 4);
int t = 0;
void t1();
void t2();
volatile boolean isinterupt[2];
void setup() {
  Serial.begin(9600);
  isinterupt[0] = 0;
  isinterupt[1] = 0;
  step1.setMaxSpeed(2000);
  step1.setSpeed(900);
  step2.setMaxSpeed(6400);
  step2.setSpeed(800);
  attachInterrupt(0,t1,FALLING);
  attachInterrupt(1, t2, FALLING);
  Serial.println("准备开始");
  while (!Serial.available());
  Serial.println("开始");
}

// the loop function runs over and over again until power down or reset
void loop() {
  if (!isinterupt[0] || !isinterupt[1])
  {
    step1.runSpeed();
    step2.runSpeed();
  }
  else
  {
    if(!t){
          Serial.println("测试成功");
          t = 1;
    }

  }
}
void t1()
{
  step1.setCurrentPosition(0);
  isinterupt[0] = 1;
  Serial.println("step1已经通过中断停止");
  detachInterrupt(0);
}

void t2()
{
  isinterupt[1] = 1;
  step2.setCurrentPosition(0);
  Serial.println("step2已经通过中断停止");
  detachInterrupt(1);
}
